package com.fa4j.code.generate.service.generator.freemarker;

import com.google.common.base.CaseFormat;
import freemarker.template.SimpleScalar;
import freemarker.template.TemplateMethodModelEx;
import freemarker.template.TemplateModelException;

import java.util.List;

public class DbFieldMethod implements TemplateMethodModelEx {
    @Override
    public Object exec(List arguments) throws TemplateModelException {
       Object value =  arguments.get(0);
       if(value instanceof SimpleScalar scalar){
          return CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, scalar.getAsString());
       }
        return value;
    }
}
